package com.jml.HashMap.ExtArrayListMap;

import java.util.ArrayList;
import java.util.List;

//基于ArrayList实现hashMap
public class ExtArrayListHashMap<Key,Value> {
	//map集合存储的容量
	private List<Entry<Key,Value>> tables = new ArrayList<Entry<Key,Value>>();
	//表示map容器的实际容量
	//private  int size;
	public void put(Key key,Value value){
		//当key相同把value覆盖
		for (Entry<Key,Value> entry: tables) {
			if(key.equals(entry.key)){
				entry.value = value;
				return;
			}
		}
		Entry entry = new Entry(key,value);
		tables.add(entry);
	}
	public Value get(Key key){
		Entry<Key, Value> entry = getEntry(key);
		return entry==null?null:entry.value;
	}
	public Entry<Key,Value> getEntry(Key key){
		for (Entry<Key,Value> entry: tables) {
			if(key.equals(entry.key)){
				return entry;
			}
		}
		return  null;
	}
}
